package priv.mill.db;

public class NameUtils {
	
	public static void main(String[] args) {
		String name = "this_is_my_info";
		String sb = under2Pasic(name);
		System.out.println(toUnder(sb));
	}

	public static String toUnder(String str) {
		StringBuilder sb=new StringBuilder();
		char[] charArray = str.toCharArray();
		int i=0;
		for (char c : charArray) {
			if(c>='A' && c<='Z' && i++>0) {
				sb.append('_');
			}
			sb.append(c);
		}
		return sb.toString().toLowerCase();
	}

	public static String under2Camel(String name) {
		String under2Pasic = under2Pasic(name);
		return under2Pasic.substring(0, 1).toLowerCase()+under2Pasic.substring(1);
	}

	public static String under2Pasic(String name) {
		StringBuilder sb=new StringBuilder();
		String[] split = name.trim().toLowerCase().split("_");
		for (String string : split) {
			if(string.trim().isEmpty())continue;
			sb.append(string.substring(0, 1).toUpperCase());
			sb.append(string.substring(1));
		}
		return sb.toString();
	}

}
